﻿using System;
using System.Windows.Forms;
using System.Drawing;
using System.Text;

namespace ProjectResistance.Shell
{
    public class DoubleBufferedForm: Form
    {
        protected Bitmap m_bmBuffer;
        protected Graphics m_gBuffer;
        public DoubleBufferedForm()
        {
            m_bmBuffer = new Bitmap(1, 1);
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            if (m_bmBuffer != null)
                m_bmBuffer.Dispose();
            if (m_gBuffer != null)
                m_gBuffer.Dispose();

            m_bmBuffer = null;
            m_gBuffer = null;

            if (Width * Height == 0)
                return;
            m_bmBuffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            m_gBuffer = Graphics.FromImage(m_bmBuffer);
        }


        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawImage(m_bmBuffer, 0, 0);
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            
        }
    }
}
